package logic

import (
	"cart_srv/cart"
	"cart_srv/internal/svc"
	"cart_srv/model/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCartLogic {
	return &UpdateCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateCartLogic) UpdateCart(in *cart.UpdateCartRequest) (*cart.UpdateCartResponse, error) {
	// todo: add your logic here and delete this line
	c := mysql.Cart{
		UserID:   uint(in.UserId),
		GoodsNum: in.Num,
		GoodsID:  in.GoodsId,
	}
	err := c.Update()
	if err != nil {
		logx.Error("修改失败:", err)
		return nil, err
	}
	return &cart.UpdateCartResponse{}, nil
}
